package com.newasia.shopping.controller;

import com.newasia.commons.result.ResponseData;
import com.newasia.commons.result.ResponseUtil;
import com.newasia.shopping.constants.ShoppingRetCode;
import com.newasia.user.IAreaService;
import com.newasia.user.dto.AreaListRequest;
import com.newasia.user.dto.AreaListResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/shopping")
public class AreaController {

    @Reference(timeout = 3000)
    IAreaService areaService;

    @GetMapping("/areas/{parentid}")
    public ResponseData areaList(@PathVariable("parentid") Integer parentId){

        AreaListRequest request = new AreaListRequest();
        request.setParentId(parentId);

        AreaListResponse response = areaService.areaList(request);
        if(response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response);
        }
        return new ResponseUtil().setErrorMsg(response);
    }
}
